package com.yunxi.controller.finance;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.finance.pojo.VehiclePriceTypeVO;
import com.yunxi.finance.service.VehiclePriceTypeDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * <p>
 * 车辆价格类型 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-21
 */
@RestController
@RequestMapping("/admin/finance/vehiclePriceType")
@Api(tags = "finance:vehiclePriceType", description = "车辆价格类型接口")
public class VehiclePriceTypeController {
    private static final Logger logger = LoggerFactory.getLogger(VehiclePriceTypeController.class);

    @Autowired
    VehiclePriceTypeDubboService baseVehiclePriceTypeDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(VehiclePriceTypeVO vehiclePriceTypeVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(baseVehiclePriceTypeDubboService.findPageByVO(vehiclePriceTypeVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询")
    public ApiResult list(VehiclePriceTypeVO vehiclePriceTypeVO) throws Exception {
        return ResponseUtil.ok(baseVehiclePriceTypeDubboService.listByVo(vehiclePriceTypeVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(baseVehiclePriceTypeDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody VehiclePriceTypeVO vehiclePriceTypeVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        baseVehiclePriceTypeDubboService.saveOrUpdate(vehiclePriceTypeVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<VehiclePriceTypeVO> vehiclePriceTypeVOList) throws RuntimeException, IllegalAccessException, InstantiationException, InvocationTargetException {
        baseVehiclePriceTypeDubboService.removeByListVo(vehiclePriceTypeVOList);
        return ResponseUtil.ok("success");
    }
}
